import wizard
import pooler
from tools.misc import UpdateableStr,UpdateableDict
import time
import operator
from osv import osv, fields
from osv.orm import intersect
import tools.sql
from tools import config
from tools.translate import _
from mx import DateTime

form_error = '''
<form string="KDVN Warning">
    <separator string='This report can print one Job only' colspan="4"/>
</form>'''


def _check(self, cr, uid, data, context):
    try:
        prj_id = data['ids']
    except:
        prj_id = data['id']
    if len(prj_id)>1:
        return 'print_error'
    
    pool = pooler.get_pool(cr.dbname)
    prj_obj = pool.get('kdvn.project')
    prj = prj_obj.browse(cr,uid,prj_id,context=context)
    
    if prj[0].project_type=='E':
        return 'print_job_e'
    else:
        return 'print_job_m'

class wizard_job_and_quotation_list(wizard.interface):
    """
    Job and Quotation List Report
    """
    states = {
              
        'init': {
            'actions': [],
            'result': {'type': 'choice','next_state':_check
                       }      
                },
        'print_error': {
            'actions': [],
            'result': {
                'type': 'form',
                'arch':form_error,
                'fields':{},
                'state':[('end','Ok','gtk-ok')]
                      }},
        'print_job_e': {
                'actions': [],
                'result': {'type':'print', 'report':'kdvn.report.job.quotation.list.electrical.hidden','state':'end'
                           }
                        },
        'print_job_m': {
                'actions': [],
                'result': {'type':'print', 'report':'kdvn.report.job.quotation.list.mechanical.hidden','state':'end'
                           }
                        },
            }
wizard_job_and_quotation_list('job_and_quotation_list')